package main

import (
	"fmt"
	"net/url"
)

func main() {
	//ParseRequestURI 将 rawurl 解析为 URL 结构。 它假定 rawurl 是在 HTTP 请求中收到的，因此 rawurl 仅被解释为绝对 URI 或绝对路径。
	//假定字符串 rawurl 没有 #fragment 后缀。 （Web 浏览器在将 URL 发送到 Web 服务器之前会删除 #fragment。）

	uri, err := url.ParseRequestURI("https://translate.google.com/?sl=en&tl=zh-CN&text=ParseRequestURI%20parses%20rawurl%20into%20a%20URL%20structure.%20It%20assumes%20that%20rawurl%20was%20received%20in%20an%20HTTP%20request%2C%20so%20the%20rawurl%20is%20interpreted%20only%20as%20an%20absolute%20URI%20or%20an%20absolute%20path.%20The%20string%20rawurl%20is%20assumed%20not%20to%20have%20a%20%23fragment%20suffix.%20(Web%20browsers%20strip%20%23fragment%20before%20sending%20the%20URL%20to%20a%20web%20server.)&op=translate")
	if err != nil {
		return
	}

	fmt.Println(uri.Query().Encode())
	//op=translate&sl=en&text=ParseRequestURI+parses+rawurl+into+a+URL+structure.+It+assumes+that+rawurl+was+received+in+an+HTTP+request%2C+so+the+rawurl+is+interpreted+only+as+an+absolute+URI+or+an+absolute+path.+The+string+rawurl+is+assumed+not+to+have+a+%23fragment+suffix.+%28Web+browsers+strip+%23fragment+before+sending+the+URL+to+a+web+server.%29&tl=zh-CN
}
